package com.so206.crond;

import com.so206.crond.process.SettPaymentThread;
import com.so206.plugins.pay.AliPayFunction;
import com.so206.plugins.pay.WxPayFunction;
import com.so206.service.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 自动打款  - 每晚10:00
 */
@Component
public class SettPaymentTask {

    private static final Logger logger = LoggerFactory.getLogger(SettPaymentTask.class);

    @Autowired
    private SettLementService settLementService;

    @Autowired
    private UserService userService;

    @Autowired
    private AliPayFunction aliPayFunction;

    @Autowired
    private WxPayFunction wxPayFunctionPC;

    @Autowired
    private WebConfigService webConfigService;

    @Autowired
    private PayConfigService payConfigService;

    @Autowired
    private AlipayConfigService alipayConfigService;

    @Autowired
    private WxPayConfigService wxPayConfigService;

    public SettPaymentTask() {
        logger.info("SettPaymentTask Init...");
    }

    /**
     * 自动打款  - 每晚10:00
     */
    @Async
    @Scheduled(cron = "0 00 09 * * ?")
    public void timerToNow() {
        logger.info("当前时间:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        SettPaymentThread thread = new SettPaymentThread(settLementService, userService,
                aliPayFunction, wxPayFunctionPC, webConfigService, payConfigService,
                alipayConfigService, wxPayConfigService, 0);
        Thread model = new Thread(thread);
        model.setDaemon(true);
        model.start();
    }

}
